package com.suning.sawp.service.impl.model;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.suning.nsfuaa.employee.dto.EmployeeInfo;
import com.suning.sawp.constants.ClerkConstants;
import com.suning.sawp.intf.storeman.StaffInfoService;
import com.suning.sawp.intf.storeman.StoreManService;
import com.suning.sawp.intf.storeman.StoreValidResult;
@Service
public class StaffInfoServiceImpl  implements StaffInfoService {
    
    @Autowired
    private StoreManService storeManService;
    
    private static final Logger LOGGER = LoggerFactory.getLogger(StaffInfoServiceImpl.class);

    @Override
    public List<StoreValidResult> validHasGuide(String storeCode, List<String> cateCodes) {
        LOGGER.info("StaffInfoServiceImpl.validHasGuide ,storeCode:{},cateCodes:{}",storeCode,cateCodes);
        
        List<StoreValidResult> resultList = new ArrayList<StoreValidResult>();
        if(StringUtils.isBlank(storeCode) || cateCodes == null ){
            LOGGER.error("StaffInfoServiceImpl.validHasGuide storeCode or cateCodes  is blank ,storeCode:{},cateCodes:{}",storeCode,cateCodes);
            return resultList;
        }
        
        for(String codeItem : cateCodes){
            if(StringUtils.isBlank(codeItem)){
                continue;
            }
            StoreValidResult detail = new StoreValidResult();
            detail.setCateCode(codeItem);
            List<EmployeeInfo> itemList = storeManService.getClerksInStoreByStoreCodeAndCateCode(storeCode, ClerkConstants.SALE_GUIDE, codeItem);
            if (CollectionUtils.isNotEmpty(itemList)) {
                List<String> ddList = new ArrayList<String>();
                for (EmployeeInfo emp : itemList) {
                    if(emp != null){
                        ddList.add(emp.getEmployeeId());
                    }
                }
                
                detail.setStaffIds(ddList);
                if(ddList.size() > 0){
                    detail.setGuideExist(true);
                }
            }      
            resultList.add(detail);
        }
        
        return resultList;
    }
    
}
